﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using OpenSocialPlugin.General;
using OpenSocialPlugin.Providers;

namespace OpenSocialPlugin
{
    public partial class SetupForm : Form
    {

        public Settings _settings;
        private GeneralSetting genset = new GeneralSetting();
        public SetupForm()
        {
            InitializeComponent();
        }

        private void SetupForm_Load(object sender, EventArgs e)
        {
            foreach (KeyValuePair<string, ISocialSite> kvp in StaticHelper.settings.Sites)
            {
                TreeNode node = new TreeNode(kvp.Value.ToString());
                node.Tag = kvp.Value;
                treeView1.Nodes[1].Nodes.Add(node);
             }

        }


        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node == treeView1.Nodes[0])
            {
                panel1.Controls.Clear();
                panel1.Controls.Add(genset);
            }
            else
            {
                ISocialSite site = e.Node.Tag as ISocialSite;
                if (site != null)
                {
                    panel1.Controls.Clear();
                    panel1.Controls.Add(site.SettingForm);
                }
            }
        }

        private void button_save_Click(object sender, EventArgs e)
        {
            ISettingForm s = genset as ISettingForm;
            genset.Save();
            foreach (TreeNode node in treeView1.Nodes[1].Nodes)
            {
                ISocialSite site = node.Tag as ISocialSite;
                if (site != null)
                {
                    ISettingForm set = site.SettingForm as ISettingForm;
                    set.Save();
                }
            }
            this.Close();
        }
    }
}
